package cn.niit.service.impl;

import cn.niit.dao.SysRoleMapper;
import cn.niit.dao.SysUserMapper;
import cn.niit.entity.SysUser;
import cn.niit.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service("sysRoleService")
public class SysRoleServiceImpl implements SysRoleService {
    //添加Dao层的引用
    @Resource
    private SysRoleMapper sysRoleMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /*@Override
    public List<RoleSelectResponseVO> getAllWithSelect() {
        return sysRoleMapper.getAllWithSelect();
    }*/

    @Override
    public Set<String> getRolesByUserCode(String userCode) {
        SysUser user = sysUserMapper.getByUserCode(userCode);
        if (user == null) {
            return Collections.emptySet();
        }
        Set<String> set = new HashSet<String>();
        List<String> list = sysRoleMapper.listUserRoles(user.getId());
        set.addAll(list);
        return set;
    }
}
